﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using Microsoft.VisualBasic;
    using APP.HELPER;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using Extra.ERP;
    using Dictionary.ERP;

    public class xucTimekeepingPrivateAdd : Common.xucBaseAddH
    {
        private CalcEdit calHour;
        private CalcEdit calMinute;
        private IContainer components = null;
        private DateEdit dtDate;
        private GroupBox groupBox1;
        private GroupControl groupControl1;
        private LabelControl labelControl1;
        private LabelControl labelControl2;
        private LabelControl labelControl3;
        private LabelControl labelControl4;
        private LabelControl labelControl5;
        private LabelControl labelControl6;
        private DateTime m_Date;
        private string m_EmployeeCode;
        private Guid m_OrderID;
        private string m_ShiftCode;
        private Guid m_TimeKeeperTableListID;
        private TimeEdit tePrivateBeginTime;
        private TimeEdit tePrivateEndTime;
        private TextEdit txtShift;

        public event SuccessEventHander Success;

        public xucTimekeepingPrivateAdd()
        {
            this.InitializeComponent();
        }

        protected override void Add()
        {
            base.Add();
        }

        private bool CheckValid(DateTime PrivateBeginTime, DateTime PrivateEndTime)
        {
            HRM_TIMEKEEPER_PRIVATE hrm_timekeeper_private = new HRM_TIMEKEEPER_PRIVATE();
            foreach (DataRow row in hrm_timekeeper_private.GetList(this.m_TimeKeeperTableListID, this.m_EmployeeCode, this.m_ShiftCode, this.m_Date).Rows)
            {
                if (Convert.ToDateTime(this.tePrivateBeginTime.EditValue.ToString()) > Convert.ToDateTime(this.tePrivateEndTime.EditValue.ToString()))
                {
                    XtraMessageBox.Show("Thời gian đi v\x00e0o kh\x00f4ng được lớn hơn thời gian đi ra! \r\nVui l\x00f2ng kiểm tra lại!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return false;
                }
                if ((this.m_OrderID != new Guid(row["OrderID"].ToString())) && ((((PrivateBeginTime > Convert.ToDateTime(row["PrivateBeginTime"].ToString())) && (PrivateBeginTime < Convert.ToDateTime(row["PrivateEndTime"].ToString()))) || ((PrivateEndTime > Convert.ToDateTime(row["PrivateBeginTime"].ToString())) && (PrivateEndTime < Convert.ToDateTime(row["PrivateEndTime"].ToString())))) || (((PrivateBeginTime < Convert.ToDateTime(row["PrivateBeginTime"].ToString())) && (PrivateEndTime > Convert.ToDateTime(row["PrivateBeginTime"].ToString()))) || ((PrivateBeginTime < Convert.ToDateTime(row["PrivateEndTime"].ToString())) && (PrivateEndTime > Convert.ToDateTime(row["PrivateEndTime"].ToString()))))))
                {
                    XtraMessageBox.Show("Khoảng thời gian giờ đi ra, đi v\x00e0o kh\x00f4ng hợp lệ! \r\nVui l\x00f2ng kiểm tra lại!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return false;
                }
            }
            long num = DateAndTime.DateDiff(DateInterval.Hour, Convert.ToDateTime(PrivateBeginTime), Convert.ToDateTime(PrivateEndTime), FirstDayOfWeek.System, FirstWeekOfYear.System);
            if ((num < 0L) || (num > 8L))
            {
                XtraMessageBox.Show("Số giờ kh\x00f4ng được b\x00e9 hơn 0 hoặc lớn hơn 8!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            return true;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        protected override void Init()
        {
            base.Init();
        }

        private HRM_TIMEKEEPER_PRIVATE InitClass()
        {
            return new HRM_TIMEKEEPER_PRIVATE { TimeKeeperTableListID = this.m_TimeKeeperTableListID, EmployeeCode = this.m_EmployeeCode, ShiftCode = this.m_ShiftCode, Date = this.m_Date, PrivateBeginTime = Convert.ToDateTime(this.tePrivateBeginTime.EditValue.ToString()), PrivateEndTime = Convert.ToDateTime(this.tePrivateEndTime.EditValue.ToString()), Hour = Convert.ToDouble(this.calHour.EditValue.ToString()), Minute = Convert.ToInt32(this.calMinute.EditValue.ToString()) };
        }

        private void InitData()
        {
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucTimekeepingPrivateAdd));
            this.txtShift = new TextEdit();
            this.labelControl1 = new LabelControl();
            this.labelControl2 = new LabelControl();
            this.dtDate = new DateEdit();
            this.tePrivateBeginTime = new TimeEdit();
            this.tePrivateEndTime = new TimeEdit();
            this.labelControl3 = new LabelControl();
            this.labelControl4 = new LabelControl();
            this.calHour = new CalcEdit();
            this.calMinute = new CalcEdit();
            this.labelControl5 = new LabelControl();
            this.labelControl6 = new LabelControl();
            this.groupControl1 = new GroupControl();
            this.groupBox1 = new GroupBox();
            ((ISupportInitialize) base.Err).BeginInit();
            base.imageCollection2.BeginInit();
            this.txtShift.Properties.BeginInit();
            this.dtDate.Properties.VistaTimeProperties.BeginInit();
            this.dtDate.Properties.BeginInit();
            this.tePrivateBeginTime.Properties.BeginInit();
            this.tePrivateEndTime.Properties.BeginInit();
            this.calHour.Properties.BeginInit();
            this.calMinute.Properties.BeginInit();
            this.groupControl1.BeginInit();
            this.groupControl1.SuspendLayout();
            base.SuspendLayout();
            base.btnSave.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            base.btnSave.Location = new Point(0x7c, 0xc2);
            base.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            base.btnCancel.Location = new Point(0x143, 0xc2);
            base.btnSaveNew.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            base.btnSaveNew.Location = new Point(0xde, 0xc2);
            base.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.txtShift.Location = new Point(0x52, 0x20);
            this.txtShift.Name = "txtShift";
            this.txtShift.Properties.ReadOnly = true;
            this.txtShift.Size = new Size(0x6b, 20);
            this.txtShift.TabIndex = 0x26;
            this.labelControl1.Location = new Point(0x12, 0x23);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x3a, 13);
            this.labelControl1.TabIndex = 0x27;
            this.labelControl1.Text = "Ca l\x00e0m việc:";
            this.labelControl2.Location = new Point(0xd5, 0x23);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x53, 13);
            this.labelControl2.TabIndex = 40;
            this.labelControl2.Text = "Ng\x00e0y chấm c\x00f4ng:";
            this.dtDate.EditValue = null;
            this.dtDate.Location = new Point(0x12b, 0x20);
            this.dtDate.Name = "dtDate";
            this.dtDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate.Properties.ReadOnly = true;
            this.dtDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate.Size = new Size(0x6d, 20);
            this.dtDate.TabIndex = 0x29;
            this.tePrivateBeginTime.EditValue = new DateTime(0x7dd, 6, 1, 0, 0, 0, 0);
            this.tePrivateBeginTime.Location = new Point(0x52, 0x63);
            this.tePrivateBeginTime.Name = "tePrivateBeginTime";
            this.tePrivateBeginTime.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.tePrivateBeginTime.Properties.Mask.EditMask = "HH:mm tt dd/MM/yyyy";
            this.tePrivateBeginTime.Size = new Size(0x86, 20);
            this.tePrivateBeginTime.TabIndex = 0x2a;
            this.tePrivateBeginTime.ParseEditValue += new ConvertEditValueEventHandler(this.tePrivateBeginTime_ParseEditValue);
            this.tePrivateEndTime.EditValue = new DateTime(0x7dd, 6, 1, 0, 0, 0, 0);
            this.tePrivateEndTime.Location = new Point(0x117, 0x63);
            this.tePrivateEndTime.Name = "tePrivateEndTime";
            this.tePrivateEndTime.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.tePrivateEndTime.Properties.Mask.EditMask = "HH:mm tt dd/MM/yyyy";
            this.tePrivateEndTime.Size = new Size(0x81, 20);
            this.tePrivateEndTime.TabIndex = 0x2b;
            this.tePrivateEndTime.ParseEditValue += new ConvertEditValueEventHandler(this.tePrivateEndTime_ParseEditValue);
            this.labelControl3.Location = new Point(0x12, 0x66);
            this.labelControl3.Name = "labelControl3";
            this.labelControl3.Size = new Size(0x2b, 13);
            this.labelControl3.TabIndex = 0x2c;
            this.labelControl3.Text = "Đi ra l\x00fac:";
            this.labelControl4.Location = new Point(0xde, 0x66);
            this.labelControl4.Name = "labelControl4";
            this.labelControl4.Size = new Size(0x33, 13);
            this.labelControl4.TabIndex = 0x2d;
            this.labelControl4.Text = "Đi v\x00e0o l\x00fac:";
            this.calHour.Location = new Point(0x52, 0x87);
            this.calHour.Name = "calHour";
            this.calHour.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.calHour.Properties.ReadOnly = true;
            this.calHour.Size = new Size(0x3e, 20);
            this.calHour.TabIndex = 0x2e;
            this.calMinute.Location = new Point(0xdf, 0x87);
            this.calMinute.Name = "calMinute";
            this.calMinute.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.calMinute.Properties.ReadOnly = true;
            this.calMinute.Size = new Size(0x3e, 20);
            this.calMinute.TabIndex = 0x2f;
            this.labelControl5.Location = new Point(0x12, 0x8a);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new Size(0x3b, 13);
            this.labelControl5.TabIndex = 0x30;
            this.labelControl5.Text = "Tổng số giờ:";
            this.labelControl6.Location = new Point(150, 0x8a);
            this.labelControl6.Name = "labelControl6";
            this.labelControl6.Size = new Size(0x43, 13);
            this.labelControl6.TabIndex = 0x31;
            this.labelControl6.Text = "Tổng số ph\x00fat:";
            this.groupControl1.Controls.Add(this.groupBox1);
            this.groupControl1.Controls.Add(this.labelControl1);
            this.groupControl1.Controls.Add(this.txtShift);
            this.groupControl1.Controls.Add(this.labelControl6);
            this.groupControl1.Controls.Add(this.labelControl2);
            this.groupControl1.Controls.Add(this.labelControl5);
            this.groupControl1.Controls.Add(this.dtDate);
            this.groupControl1.Controls.Add(this.calMinute);
            this.groupControl1.Controls.Add(this.tePrivateBeginTime);
            this.groupControl1.Controls.Add(this.calHour);
            this.groupControl1.Controls.Add(this.tePrivateEndTime);
            this.groupControl1.Controls.Add(this.labelControl4);
            this.groupControl1.Controls.Add(this.labelControl3);
            this.groupControl1.Dock = DockStyle.Top;
            this.groupControl1.Location = new Point(0, 0);
            this.groupControl1.Name = "groupControl1";
            this.groupControl1.Size = new Size(0x1af, 180);
            this.groupControl1.TabIndex = 0x33;
            this.groupControl1.Text = "Th\x00f4ng Tin L\x00e0m Việc Ri\x00eang";
            this.groupBox1.ForeColor = Color.Blue;
            this.groupBox1.Location = new Point(0x12, 0x47);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(390, 0x10);
            this.groupBox1.TabIndex = 0x33;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Thời gian l\x00e0m việc ri\x00eang";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.groupControl1);
            base.Name = "xucTimekeepingPrivateAdd";
            base.Size = new Size(0x1af, 0xea);
            base.Controls.SetChildIndex(base.btnCancel, 0);
            base.Controls.SetChildIndex(base.btnSave, 0);
            base.Controls.SetChildIndex(base.btnSaveNew, 0);
            base.Controls.SetChildIndex(this.groupControl1, 0);
            ((ISupportInitialize) base.Err).EndInit();
            base.imageCollection2.EndInit();
            this.txtShift.Properties.EndInit();
            this.dtDate.Properties.VistaTimeProperties.EndInit();
            this.dtDate.Properties.EndInit();
            this.tePrivateBeginTime.Properties.EndInit();
            this.tePrivateEndTime.Properties.EndInit();
            this.calHour.Properties.EndInit();
            this.calMinute.Properties.EndInit();
            this.groupControl1.EndInit();
            this.groupControl1.ResumeLayout(false);
            this.groupControl1.PerformLayout();
            base.ResumeLayout(false);
        }

        private void RaiseSuccessEventHander(HRM_TIMEKEEPER_PRIVATE item)
        {
            if (this.Success != null)
            {
                this.Success(this, item);
            }
        }

        public void SetData(HRM_TIMEKEEPER_PRIVATE item)
        {
            SYS_LOG.Insert("Tăng Cường Sau Ca L\x00e0m Việc", "Xem", item.OrderID.ToString());
            this.m_TimeKeeperTableListID = item.TimeKeeperTableListID;
            this.m_EmployeeCode = item.EmployeeCode;
            this.m_ShiftCode = item.ShiftCode;
            this.m_Date = item.Date;
            this.m_OrderID = item.OrderID;
            DIC_SHIFT dic_shift = new DIC_SHIFT();
            dic_shift.Get(this.m_ShiftCode);
            this.txtShift.Text = dic_shift.ShiftName;
            this.dtDate.DateTime = item.Date;
            this.tePrivateBeginTime.EditValue = item.PrivateBeginTime;
            this.tePrivateEndTime.EditValue = item.PrivateEndTime;
            this.calHour.EditValue = item.Hour;
            this.calMinute.EditValue = item.Minute;
        }

        public void SetData(Guid TimeKeeperTableListID, string EmployeeCode, string ShiftCode, DateTime Date)
        {
            SYS_LOG.Insert("Tăng Cường Sau Ca L\x00e0m Việc", "Xem", "");
            this.m_TimeKeeperTableListID = TimeKeeperTableListID;
            this.m_EmployeeCode = EmployeeCode;
            this.m_ShiftCode = ShiftCode;
            this.m_Date = Date;
            DIC_SHIFT dic_shift = new DIC_SHIFT();
            dic_shift.Get(this.m_ShiftCode);
            this.txtShift.Text = dic_shift.ShiftName;
            this.dtDate.DateTime = this.m_Date;
            this.tePrivateBeginTime.EditValue = new DateTime(this.m_Date.Year, this.m_Date.Month, this.m_Date.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            this.tePrivateEndTime.EditValue = new DateTime(this.m_Date.Year, this.m_Date.Month, this.m_Date.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            this.calHour.EditValue = 0;
            this.calMinute.EditValue = 0;
        }

        private void tePrivateBeginTime_ParseEditValue(object sender, ConvertEditValueEventArgs e)
        {
            this.calMinute.EditValue = DateAndTime.DateDiff(DateInterval.Minute, Convert.ToDateTime(this.tePrivateBeginTime.EditValue.ToString()), Convert.ToDateTime(this.tePrivateEndTime.EditValue.ToString()), FirstDayOfWeek.System, FirstWeekOfYear.System);
            double num = Math.Round((double) (Convert.ToDouble(this.calMinute.EditValue.ToString()) / 60.0), 1);
            this.calHour.EditValue = num;
        }

        private void tePrivateEndTime_ParseEditValue(object sender, ConvertEditValueEventArgs e)
        {
            this.calMinute.EditValue = DateAndTime.DateDiff(DateInterval.Minute, Convert.ToDateTime(this.tePrivateBeginTime.EditValue.ToString()), Convert.ToDateTime(this.tePrivateEndTime.EditValue.ToString()), FirstDayOfWeek.System, FirstWeekOfYear.System);
            double num = Math.Round((double) (Convert.ToDouble(this.calMinute.EditValue.ToString()) / 60.0), 1);
            this.calHour.EditValue = num;
        }

        protected override string uc_Change()
        {
            return string.Empty;
        }

        protected override string uc_Delete()
        {
            HRM_TIMEKEEPER_PRIVATE item = this.InitClass();
            string str = item.Delete();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            return str;
        }

        protected override string uc_Save()
        {
            SYS_LOG.Insert("Tăng Cường Sau Ca L\x00e0m Việc L\x00e0m Việc", "Th\x00eam", "");
            if (!this.CheckValid(Convert.ToDateTime(this.tePrivateBeginTime.EditValue.ToString()), Convert.ToDateTime(this.tePrivateEndTime.EditValue.ToString())))
            {
                return "FALSE";
            }
            HRM_TIMEKEEPER_PRIVATE item = new HRM_TIMEKEEPER_PRIVATE();
            item = this.InitClass();
            if (item == null)
            {
                return "FALSE";
            }
            base.SetWaitDialogCaption("Đang lưu dữ liệu...");
            item.OrderID = Guid.NewGuid();
            string text = item.Insert();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            Cursor.Current = Cursors.Default;
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.DoHide();
            return text;
        }

        protected override string uc_Update()
        {
            SYS_LOG.Insert("Tăng Cường Sau Ca L\x00e0m Việc L\x00e0m Việc", "Cập Nhật", this.m_OrderID.ToString());
            if (!this.CheckValid(Convert.ToDateTime(this.tePrivateBeginTime.EditValue.ToString()), Convert.ToDateTime(this.tePrivateEndTime.EditValue.ToString())))
            {
                return "FALSE";
            }
            base.SetWaitDialogCaption("Đang cập nhật dữ liệu...");
            HRM_TIMEKEEPER_PRIVATE item = new HRM_TIMEKEEPER_PRIVATE();
            item = this.InitClass();
            item.OrderID = this.m_OrderID;
            string text = item.Update();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.DoHide();
            return text;
        }

        public delegate void SuccessEventHander(object sender, HRM_TIMEKEEPER_PRIVATE item);
    }
}

